#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

#define STDIN
//#define DEBUG
#define MAX 9999999

int T;
int E, F;
int N;
int PW[501][2];
int P, W;
int f[50010];

int compare(int *a, int *b)
{
    if ((float)(*a) / *(a+1) > (float)(*b) / *(b+1))
    {
        return 1;
    }
    return -1;
}

void process()
{
    int i, j;

    qsort(PW, N, sizeof(PW[0]), &compare);

#ifdef DEBUG
    for (i = 0; i < N; ++i)
    {
        printf("%d %d\n", PW[i][0], PW[i][1]);
    }
#endif

    memset(f, MAX, sizeof(f)); 

    int V = F - E;

    f[0] = 0;
    for (i = 0; i < N; ++i)
    {
        for (j = 0; j <= V; ++j)
        {
            if (j >= PW[i][1])
                f[j] = 
                    fmin(
                            f[j], 
                            f[j-PW[i][1]] + PW[i][0]
                        );
        }
    }

#ifdef DEBUG
    for (i = 0; i <= V; ++i)
    {
        printf("%d\t", f[i]);
    }
    printf("\n");
#endif

    if (f[V] < MAX)
    {
        printf("The minimum amount of money in the piggy-bank is %d.\n", f[V]);
    }
    else
    {
        printf("This is impossible.\n");
    }
}

int main()
{
#if defined(STDIN)
    freopen("bin/1384.in", "r", stdin);
#endif

    scanf("%d", &T);

    int i;
    for (i = 0; i < T; ++i)
    {
        scanf("%d %d", &E, &F);
        scanf("%d", &N);
        int j;
        for (j = 0; j < N; ++j)
        {
            scanf("%d %d", &PW[j][0], &PW[j][1]);
        }
        process();
    }
    return 0;
}
